<?php
  require_once(ROOT_PATH.'ty/database_conf.php');
  require_once(ROOT_PATH.'ty/DataBaseDao.php');
  class NewsService extends dataBaseDao{
      
      /*  
      *  读取首页显示的文章信息
      */
      public function getNewsShowToIndexGroupCat(){
          
          $catList = $this->getCategoryOfIndex();
          foreach($catList as $k=>$v){
              $catList[$k]['news_list'] = $this->getNewsByCat($v['cate_id']);
          }
          
          $this->getDb()->close();
          return $catList;          
      }
      
      public function getNewsContentHtml($catList){
          $html = '';
          $index = 0;
          foreach($catList as $k=>$v){
              $html .= '<div class="news" ';
              if($index%2==1){
                $html .= 'style="padding-left:10px;"';                  
              }
              $html .= ' >';
              
              $html .= '<h3 class="category_title">';
              $html .= '<span style="font-size:14px;">'.$v['cate_title'].'</span>';
              $html .= '<a href="#"><span class="more1"></span></a>';
              $html .= '</h3><ul >';
              foreach($v['news_list'] as $fk=>$fv){
                  $html .= '<li><a style="border-bottom:1px solid #666666;">'.$fv['news_title'].'</a></li>';
              }
              $html .= '</ul></div>';
              
          }
          
          return $html;
      }
      
      public function getCategoryOfIndex(){
          $sql = "select * from news_category where is_show_index=1 order by order_no asc ";
          
          return $this->getDb()->fetchRows($sql);
      }
      
      public function getNewsByCat($catId){
          if(empty($catId)){
              return false;
          }
          
          $sql = "select * from ty_news where category_id=$catId order by update_date desc ";
          return $this->getDb()->fetchRows($sql);
      }
      
      
  }
  
  
?>
